<!--
 * @Author: wangming
 * @Date: 2021-05-31 10:56:38
 * @LastEditors: wangming
 * @LastEditTime: 2022-07-13 09:33:24
 * @Description: file content
-->
<template>
  <universal
    :formList="formList"
    :hmpageInfo="hmpageInfo"
    :formData="formData"
    v-if="hmpageInfo"
  ></universal>
</template>

<script>
import universal from "./index";
import { mapActions } from "vuex";
import {
  getHmpageInfoKey,
  getHmpageInfo,
} from "@/apis/paas/HmPageController.js";
import { postHmhttprequestdefinitionExecute } from "@/apis/paas/HmHttpRequestDefinitionController.js";
import { getMenupermissionconfigBypage } from "@/apis/paas/HmMenuPermissionConfigController.js";
export default {
  async mounted() {
    if (process.env.VUE_APP_USER === "APP") {
      let { json } = await this.getJSON("getJSONkeep");
      let { FormData } = JSON.parse(json);
      if (FormData.keepAlive) {
        this.setRouteAlive(this.$route.fullPath);
      }
    }
    this.initAuth();
    this.getHmpageInfoKeyInit();
  },
  activated() {
    if (!!this.name) {
      this.setViewTitle({ route: this.$route, title: this.name });
    }
  },
  data() {
    return {
      formData: {},
      hmpageInfo: null,
      formList: [],
      name: "",
    };
  },
  methods: {
    ...mapActions(["setViewTitle", "setAuthBypage", "setRouteAlive"]),
    async initAuth() {
      let { superAdmin, buttons } = await getMenupermissionconfigBypage(
        {
          pageKey: this.$route.query.pageKey || this.$route.query.pageId,
        },
        { vuekey: "getMenupermissionconfigBypage" }
      );
      if (superAdmin) {
        this.setAuthBypage([]);
      } else {
        this.setAuthBypage(buttons);
      }
    },
    getJSON(vuekey = "getJSON") {
      if (!!this.$route.query.pageKey) {
        return getHmpageInfoKey(
          {
            key: this.$route.query.pageKey,
            includeJson: true,
          },
          { vuekey }
        );
      } else {
        return getHmpageInfo(
          {
            id: this.$route.query.pageId,
            includeJson: true,
          },
          { vuekey }
        );
      }
    },
    async getHmpageInfoKeyInit() {
      if (!!this.$route.query.id) {
        this.formData =
          (await postHmhttprequestdefinitionExecute(
            {
              key: "selectOne",
              pageId: this.$route.query.pageId,
              pageKey: this.$route.query.pageKey,
              values: { id: this.$route.query.id },
            },
            { vuekey: "postHmhttprequestdefinitionExecute" }
          )) || {};
        let values = this.formData._VALUES_ || {};
        Object.assign(this.formData, values, { _VALUES_: undefined });
      }
      let { json, name } = await this.getJSON();
      if (!this.$route.query.title && !this.$route.meta.showMenu) {
        this.setViewTitle({ route: this.$route, title: name });
        this.name = name;
      }
      if (!!json) {
        let { FormData, formList } = JSON.parse(json);
        this.formList = formList;
        this.hmpageInfo = FormData;
      }
    },
  },
  components: { universal },
};
</script>
